<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Setting extends CI_Controller {
 	public function __construct()
    {
        parent::__construct();
        session_start();
        //$this->output->enable_profiler(FALSE);
    	if (!isset($_SESSION['uid']) || $_SESSION['uid'] < 1){
	    	redirect('memberlogin/requiredmessage','refresh');
	    }
	    elseif ($_SESSION['role_id'] !=1){
    		redirect('memberlogin/restriction','refresh');
	    }
        $data['menus'] = 'menus';
	    $data['left'] = 'hr/setting_left';
		$this->load->vars($data);
    }
	    
	public function index()
	{
		$data['title'] = "Setting - Friends-International Organization";
		$data['main'] = 'setting/setting';
		$this->load->vars($data);
		$this->load->view('template'); 
	}
	
/** Position List */
	function positionlist()
	{
		$data['title'] = "Position List";
		$data['main'] = 'hr/positionlist';
		$data['positions'] = $this->MPosition->getAllPositions();
		$this->load->vars($data);
		$this->load->view('template');  
	}
	
	function createposition()
	{
		if ($this->input->post('title')){
			$this->MPosition->addPosition();
	  		$this->session->set_flashdata('message','Position added');
	  		redirect('setting/positionlist','refresh');
		}else {
			$data['title'] = "Create new Position";
			$data['main'] = 'hr/positionadd';
			$this->load->vars($data);
			$this->load->view('template');
		}  
	}
	
	function editposition($id=0)
	{
		if ($this->input->post('title')){
			$this->MPosition->updatePosition();
	  		$this->session->set_flashdata('message','Position updated');
	  		redirect('setting/positionlist','refresh');
		}else {
			$data['title'] = "Edit Position";
			$data['main'] = 'hr/positionedit';
			$data['position'] = $this->MPosition->getPosition($id);
			$this->load->vars($data);
			$this->load->view('template');
		}  
	}
/** End Position */

/** Team List */
	function teamlist()
	{
		$data['title'] = "Team List";
		$data['main'] = 'hr/teamlist';
		$data['teams'] = $this->MTeam->getAllTeams();
		$this->load->vars($data);
		$this->load->view('template');  
	}
	
	function createteam()
	{
		if ($this->input->post('TeamName')){
			$this->MTeam->addTeam();
	  		$this->session->set_flashdata('message','Team added');
	  		redirect('setting/teamlist','refresh');
		}else {
			$data['title'] = "Create new Team";
			$data['main'] = 'hr/teamadd';
			$this->load->vars($data);
			$this->load->view('template');
		}  
	}
	
	function editteam($id=0)
	{
		if ($this->input->post('TeamName')){
			$this->MTeam->updateTeam();
	  		$this->session->set_flashdata('message','Team updated');
	  		redirect('setting/teamlist','refresh');
		}else {
			$data['title'] = "Edit Team";
			$data['main'] = 'hr/teamedit';
			$data['team'] = $this->MTeam->getTeam($id);
			$this->load->vars($data);
			$this->load->view('template');
		}  
	}
/** End Team */
}
